<?php

/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

class Session
{
	private $session_id;
	private $session_data;
	
	protected function __construct()
	{
		session_start();
		
		$this->session_id = session_id();
		$this->session_data = &$_SESSION;
	}
	
	function GetSessionId()
	{
		return $this->session_id;
	}
	
	function GetVar($field, $default=null)
	{
		if ( array_key_exists($field, $this->session_data) )
		{
			return $this->session_data[$field];
		}
		else
		{
			return $default;
		}
	}
	
	function SaveVar($field, $value)
	{
		$this->session_data[$field] = $value;
	}
	
	function DelVar($field)
	{
		if ( array_key_exists($field, $this->session_data) )
		{
			unset($this->session_data[$field]);
		}
	}
	
	function SaveStatus($status)
	{	
		$this->session_data['status'] = $status;
	}
	
	function HasStatus()
	{
		if ( (array_key_exists('status', $this->session_data) ? $this->session_data['status'] : null) != null )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	function GetStatus()
	{
		$status = $this->session_data['status'];

		unset($this->session_data['status']);
		
		return $status;
	}
	
	function Redirect($page)
	{
		header( "Location: http://".$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER['PHP_SELF']), '/\\')."/".$page );
		exit();
	}
}

?>